import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;

import static org.opencv.highgui.HighGui.imshow;
import static org.opencv.highgui.HighGui.waitKey;
import static org.opencv.imgcodecs.Imgcodecs.imread;
import static org.opencv.imgcodecs.Imgcodecs.imwrite;
import static org.opencv.imgproc.Imgproc.COLOR_RGB2GRAY;
import static org.opencv.imgproc.Imgproc.cvtColor;

public class App {
    public static void main(String[] args) {
// 解决awt报错问题
        System.setProperty("java.awt.headless", "false");
        System.load("/usr/share/java/opencv4/libopencv_java452.so");
        // 读取图像
        Mat image = imread("hello.jpg");
        if (image.empty()) {
            System.out.println("image is empty");
        }

        // 创建输出单通道图像
        Mat grayImage = new Mat(image.rows(), image.cols(), CvType.CV_8SC1);
        // 进行图像色彩空间转换:
        cvtColor(image, grayImage, COLOR_RGB2GRAY);

        imwrite("hello2.jpg", grayImage);
    }
}
